package com.hqm.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.hqm.meta.Product;

@Repository("productDao")
public interface ProductDao {
	@Insert("INSERT content(title, summary, detail, price, icon) "
			+ "VALUES(#{title}, #{summary}, #{detail}, #{price}, #{icon})")
	Integer addProduct(Product product);
	
	@Delete("DELETE FROM content WHERE id=#{id}")
	Integer deleteProductById(@Param("id") Integer id);
	
	@Update("UPDATE content SET title=#{title}, summary=#{summary}, detail=#{detail}, "
			+ "price=#{price}, icon=#{icon} WHERE id=#{id}")
	Integer updateProduct(Product product);
	
	@Select("SELECT * FROM content WHERE id=#{id}")
	Product getProductById(@Param("id") Integer id);
	
	@Select("SELECT * FROM content WHERE title=#{title}")
	Product getProductByTitle(@Param("title") String title);
	
	@Select("SELECT * FROM content WHERE icon=#{icon}")
	Product getProductByImage(@Param("icon") String icon);
	
	@Select("SELECT * FROM content")
	List<Product> getAllProducts();
}
